import MysqlServer from "../utils/connect";
import {ISqlInsert} from "../../global";

export interface IRecently {
    key: string
    recentlyUID: string;
    userUID: number;
    path: string;
    name: string
    describe: string
    time: string
}

export const recentlyListDao = async (params: Array<string>) => {
    return await MysqlServer.sqlAsync<Array<IRecently>, Array<string>>("SELECT * FROM t_recently WHERE `userUID` = ? AND `name` LIKE ? ORDER BY `time` DESC", params)
}

export const addRecentlyDao = async (params: Array<string>) => {
    return await MysqlServer.sqlAsync<ISqlInsert, Array<string>>("INSERT INTO t_recently(`recentlyUID`, `userUID`, `path`, `name`, `describe`, `time`) VALUES(?, ?, ?, ?, ?, ?)", params)
}

export const delRecentlyDao = async (params: Array<Array<string>>) => {
    return await MysqlServer.sqlAsync<ISqlInsert, Array<Array<string>>>("DELETE FROM t_recently WHERE recentlyUID IN (?)", params)
}

export const recentlyViewDao = async (params: Array<string>) => {
    return await MysqlServer.sqlAsync<Array<IRecently>, Array<string>>("SELECT * FROM t_recently WHERE path = ?", params)
}

export const editRecentlyDao = async (params: Array<string>) => {
    return await MysqlServer.sqlAsync<ISqlInsert, Array<string>>("UPDATE t_recently SET `name` = ?, `describe` = ? WHERE `path` = ?", params)
}